﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    internal class DesertPermissionService : IDesertPermissionService
    {
        private IDesertPermissionDal _desertPermission;
        private IMapper _mapper;
        public DesertPermissionService(IDesertPermissionDal desertPermission, IMapper mapper)
        {
            _desertPermission = desertPermission;
            _mapper = mapper;
        }

        public async Task<int> AddDesertPermissionAsync(int staffId, string[] deserId)
        {
            return await _desertPermission.AddAsync(new Desertpermission 
            {
                StaffId = staffId,
                DesertId = deserId.ToString()
            });
        }

        public async Task<int> DeleteDesertPermissionAsync(int id)
        {
            var data = await _desertPermission.QueryAsync(id);
            return data == null ? -1 : await _desertPermission.DeleteAsync(data);
        }

        public async Task<int> EditDesertPermissionAsync(int id, int staffId, string[] deserId)
        {
            var data = await _desertPermission.QueryAsync(id);
            if (data == null)
                return -1;
            data.StaffId = staffId;
            data.DesertId = deserId.ToString();
            return await _desertPermission.EditAsync(data);
        }

        public async Task<List<DesertPermissionDto>> GetDesertPermissionAllAsync()
        {
            var data = await _desertPermission.QueryAsync();
            return _mapper.Map<List<Desertpermission>,List<DesertPermissionDto>>(data);
        }

        public async Task<DesertPermissionDto> QueryDesertPermissionByIdAsync(int id)
        {
            var data = await _desertPermission.QueryAsync(id);
            return _mapper.Map<Desertpermission,DesertPermissionDto>(data);
        }
    }
}
